home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
nvdc87
/
lcv1n1
/
mean3.c
< prev
next >
Wrap
Text File
|
1987-08-12
|
835b
|
28 lines
/* Listing 7 -- a fast mean function in Turbo C */
#include <stdio.h>
void mean(double *list);
main()
{
double list[7000]; /* Create a list of reals to process */
double i; /* The time to do this isn't included */
/* in the benchmark. */
for(i = 1; i < 7000; i++)
list[i]=i;
mean(list); /* Call subroutine, mean */
/* to calculate. */
}
void mean(double *list) {
int i;
double x = 0, z;
puts("start"); /* Start timing here */
for(i = 1; i < 6999; i++){
x = list[i] + x; /* Add each element of */
} /* the array. */
z = x/i; /* Divide by count */
printf("%f\n",z); /* Print result */
}